﻿using BCCommon;
using BCCommon.TMS.Transport;
using BCDto.TMS.VehicleTransportBusinessConfigOverwrite;
using BCService.TMS.VehicleTransportBusinessConfigOverwrite;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.VehicleTransportBusinessConfig
{
    /// <summary>
    /// 车辆运输业务配置重写
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class VehicleTransportBusinessConfigOverwriteController : ManagementBaseController
    {
        private readonly IVehicleTransportBusinessConfigOverwriteService vehicleTransportBusinessConfigOverwriteService;

        public VehicleTransportBusinessConfigOverwriteController(IVehicleTransportBusinessConfigOverwriteService vehicleTransportBusinessConfigOverwriteService)
        {
            this.vehicleTransportBusinessConfigOverwriteService = vehicleTransportBusinessConfigOverwriteService;
        }

        /// <summary>
        /// 添加车辆运输业务配置重写
        /// </summary>
        /// <param name="requestDto">车辆运输业务配置新增重写信息</param>
        /// <response code="201">添加车辆运输业务配置重写</response>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(VehicleTransportBusinessConfigOverwriteDto), 201)]
        [Log("添加车辆运输业务配置")]
        public IActionResult Post([FromBody] VehicleTransportBusinessConfigOverWriteRequestDto requestDto)
        {
            var result = this.vehicleTransportBusinessConfigOverwriteService.Create(this.Admin, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改车辆运输业务配置重写
        /// </summary>
        /// <param name="vehicleTransportBusinessConfigOverwriteId">车辆运输业务配置重写Id</param>
        /// <param name="putDto">车辆运输业务配置修改信息</param>
        /// <response code="200">修改车辆运输业务配置重写</response>
        /// <returns></returns>
        [HttpPut("{vehicle_transport_business_config_overwrite_id}")]
        [ProducesResponseType(typeof(VehicleTransportBusinessConfigOverwriteDto), 200)]
        [Log("修改车辆运输业务配置重写")]
        public IActionResult Put([FromRoute(Name = "vehicle_transport_business_config_overwrite_id")]int vehicleTransportBusinessConfigOverwriteId,
            [FromBody] VehicleTransportBusinessConfigOverwritePutDto putDto)
        {
            var result = this.vehicleTransportBusinessConfigOverwriteService.Update(this.Admin, vehicleTransportBusinessConfigOverwriteId, putDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 删除车辆运输业务配置重写
        /// </summary>
        /// <param name="vehicleTransportBusinessConfigOverwriteId">车辆运输业务配置重写Id</param>
        /// <response code="204">删除车辆运输业务配置重写</response>
        /// <returns></returns>
        [HttpDelete("{vehicle_transport_business_config_overwrite_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        [Log("删除车辆运输业务配置重写")]
        public IActionResult Delete([FromRoute(Name = "vehicle_transport_business_config_overwrite_id")] int vehicleTransportBusinessConfigOverwriteId)
        {
            this.vehicleTransportBusinessConfigOverwriteService.Delete(this.Admin, vehicleTransportBusinessConfigOverwriteId);
            return NoContent();
        }

        /// <summary>
        /// 启用/禁用车辆运输业务配置重写
        /// </summary>
        /// <param name="vehicleTransportBusinessConfigOverwriteId">车辆运输业务配置重写Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="200">启用/禁用车辆运输业务配置重写</response>
        /// <returns></returns>
        [HttpPut("[action]/{vehicle_transport_business_config_overwrite_id}/{enabled}")]
        [ProducesResponseType(typeof(VehicleTransportBusinessConfigOverwriteDto), 200)]
        [Log("启用/禁用车辆运输业务配置重写")]
        public IActionResult Enabled([FromRoute(Name = "vehicle_transport_business_config_overwrite_id")] int vehicleTransportBusinessConfigOverwriteId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            var result = this.vehicleTransportBusinessConfigOverwriteService.UpdateEnabled(this.Admin, vehicleTransportBusinessConfigOverwriteId, enabled);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取车辆运输业务配置重写(分页)
        /// </summary>
        /// <param name="transportBusiness">运输业务</param>
        /// <param name="provinceCode">省份编码</param>
        /// <param name="cityCode">市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取车辆运输业务配置</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<VehicleTransportBusinessConfigOverwriteViewDto>), 200)]
        public IActionResult Query([FromQuery(Name = "transport_business")] TransportBusinessType? transportBusiness,
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "city_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            long? agentRecordId = null;
            if (this.Admin.AgentRecord != null)
            {
                agentRecordId = this.Admin.AgentRecord.AgentRecordId;
            }
            var result = this.vehicleTransportBusinessConfigOverwriteService.Query(agentRecordId, transportBusiness, provinceCode, cityCode, countyCode, pageIndex, pageSize);
            return this.Ok(result);
        }
    }
}
